using System;
using Jink.Core.Converters.Annotations;

namespace Jink.Core.Converters.Default
{
    [Converter]
    internal static class NullableConverters
    {
        [Converter(Weight = 0.001)]
        public static D ConvertFromNullable_N2S<S, D>(S? obj)
            where S : struct
        {
            return obj.HasValue ? obj.Value.Convert<D>() : (D)(Object)null;
        }

        [Converter(Weight = 0.001)]
        public static D? ConvertFromNullable_N2N<S, D>(S? obj)
            where S : struct
            where D : struct
        {
            return obj.HasValue ? (D?)obj.Value.Convert<D>() : null;
        }

        [Converter(Weight = 0.001)]
        public static D? ConvertFromNullable_S2N<S, D>(S obj)
            where S : struct
            where D : struct
        {
            return obj.Convert<D>();
        }
    }
}